package com.yummy.service.impl;

import com.yummy.entity.User;
import com.yummy.mapper.UserMapper;
import com.yummy.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Service
public class UserServiceImpl implements UserService {


    @Autowired
    UserMapper userMapper;


    @Override
    public int addUser(User user) {
        int i = userMapper.insertSelective(user);

        /*System.out.println(i);*/
        return i;
    }

    @Override
    public int modifyUser(User user) {
        int i = userMapper.updateByPrimaryKeySelective(user);
        /*System.out.println(i);*/
        return i;
    }

    @Override
    public int removeUser(int uId) {
        int i = userMapper.deleteByPrimaryKey(uId);
        System.out.println(i);
        return i;
    }
    /**
    * 逻辑删除  改status
     */
    @Override
    public int deleteUser(int uId) {
        User user = new User();
        user.setId(uId);
        user.setStatus(1);
        int i = userMapper.updateByPrimaryKeySelective(user);
        return i;
    }

    @Override
    public User login(String name, String password) {
        return userMapper.selectByNameAndPassword(name,password);
    }

    @Override
    public User findUserByName(String name) {
        return null;
    }

    @Override
    public User findUserById(String userId) {
        return userMapper.selectByPrimaryKey(userId);
    }
}
